@namespace BlazorComponent
@inherits BDomComponentBase
@typeparam TItem

<div class="@CssProvider.GetClass(this)" style="@CssProvider.GetStyle(this)" id="@Id">
    <div class="@CssProvider.GetClass(this,"control")">
        <div class="@CssProvider.GetClass(this,"slot")"
             @onclick="Click"
             @ref="Ref"
             tabindex="0"
             style="outline:none"
             @onblur="HandleOnBlur">

            @if (Outlined)
            {
                <fieldset>
                    <legend style="@LegendStyle">
                        <span>@((MarkupString)"&#8203;")</span>
                    </legend>
                </fieldset>
            }

            <div class="@CssProvider.GetClass(this,"select-slot")">
                @if (!string.IsNullOrWhiteSpace(Label))
                {
                    if (!Solo || Solo && !_text.Any())
                    {
                        <label class="@CssProvider.GetClass(this,"label")" style="@CssProvider.GetStyle(this,"label")">@Label</label>
                    }
                }
                <div class="@CssProvider.GetClass(this,"selector")">
                    @if (Chips)
                    {
                        @foreach (var item in _text)
                        {
                            <SlotComponent Description="SlotProvider.GetSlot<BChip>()">@item</SlotComponent>
                        }
                    }
                    else
                    {
                        @for (var i = 0; i < _text.Count(); i++)
                        {
                            var item = _text.ElementAt(i);
                            if (i == _text.Count() - 1)
                            {
                                <div class="@CssProvider.GetClass(this,"selected")">@item</div>
                            }
                            else
                            {
                                <div class="@CssProvider.GetClass(this,"selected")">@($"{item}, ")</div>
                            }
                        }
                    }
                    <input id="input-@Id" type="text" readonly="readonly"
                           class="@CssProvider.GetClass(this,"select-input")" />
                </div>
                <div class="@CssProvider.GetClass(this,"select-arrow")">
                    <div class="@CssProvider.GetClass(this,"select-arrow-icon")">
                        <SlotComponent Description="SlotProvider.GetSlot<BIcon>()">
                            @_icon
                        </SlotComponent>
                    </div>
                </div>
                <input type="hidden" value="@(Multiple ? string.Join(',', Values) : Value)" />
            </div>
            <SlotComponent Description="SlotProvider.GetSlot<BPopover>()">
                <SlotComponent Description="SlotProvider.GetSlot<BList>()">
                    <SlotComponent Description="SlotProvider.GetSlot<BListItemGroup>()">
                        <CascadingValue Value="this">
                            @foreach (var item in Items)
                            {
                                <SlotComponent Description="SlotProvider.GetSlot<BSelectOption<TItem>>()"
                                           Value="@item"
                                           Key="@(ItemValue?.Invoke(item) ?? item.ToString())"
                                           Checked="@IsSelected(item)">
                                    @(ItemText?.Invoke(item) ?? item.ToString())
                                </SlotComponent>
                            }
                        </CascadingValue>
                    </SlotComponent>
                </SlotComponent>
            </SlotComponent>
        </div>
        <div class="@CssProvider.GetClass(this,"hit")">
            <SlotComponent Description="SlotProvider.GetSlot<BHitMessage>()">@Hint</SlotComponent>
        </div>
    </div>
</div>

<SlotComponent Description="SlotProvider.GetSlot<BOverlay>()" />